<?php
/**
 * Controller_Index
 * Класс Controller_Index отвечает за главную страницу
 * 
 * @author Sayp
 */
class Controller_Index extends Controller_Base {
	
	public function action() {
		$this->actionIndex();
	}
	
	/**
	 * Главная страница
	 */
	private function actionIndex() {
		$objCity = City::getCity();
		
	//	Country::updateMinPrices();
		
		//$arrTours = Lvl_Tour::getTours();
		$objCountries = new Country();
		$arrCountries = $objCountries->find('all', array(
			'select' => '`country_name`, `country_url`, `iso`, `ID_photo`, `price_min`',
			'joins' => 'INNER JOIN `article` ON `ID_essence` = `ID_country` AND `ID_city` = ' . $objCity->id . ' AND `is_main` = 1 AND `ID_essence_type` = ' . Country::getEssenceType()
		));
		shuffle($arrCountries);
		$arrCountries = array_slice($arrCountries, 0, 8);
		
		$objArticle = new Article();
		$objArticle->find('first', array(
			'conditions' => '`is_main` = 1 AND `ID_city` = ' . $objCity->id
		));
		
		$this->title = '101 тур';
		$this->pageHead = 'Поиск тура среди всех туроператоров';
		$text = '';
		
		if ($objArticle->id) {
			if ($objArticle->getField('article_title')) $this->title = $objArticle->getField('article_title');
			if ($objArticle->getField('article_pagehead')) $this->pageHead = $objArticle->getField('article_pagehead');
			if ($objArticle->getField('article_description')) $this->description = $objArticle->getField('article_description');
			if ($objArticle->getField('article_keywords')) $this->keywords = $objArticle->getField('article_keywords');
			if ($objArticle->getField('article_text')) $text = $objArticle->getField('article_text');
		}
		
		$this->bodyClass = 'index';
		$this->showHeader();
 			View_Block::showSearchForm($objCity);
			View_Article::showArticleText($text);
			View_Block::popularDestinations($objCity, $arrCountries);
			//View_Tour::showTourBlocks($arrTours, $objCity);
		$this->showFooter();
	}
	
}